<!DOCTYPE html>
<html>
<head>
  <link rel="chrome-webstore-item">
</head>
<body>
<script>
  function runTest(galleryUrl) {
    var receivedProgressUpdate = false;

    // Link URL has to be generated dynamically in order to include the right
    // port number. The ID corresponds to the data in the "extension" directory.
    document.getElementsByTagName('link')[0].href =
        galleryUrl + '/detail/ecglahbcnmdpdciemllbhojghbkagdje';

    try {
      // Ensure our listener mask works correctly by adding both listeners.
      // We don't need to test the fucntionality, as each listener is tested
      // individually separately.
      chrome.webstore.onDownloadProgress.addListener(function(progress) {});
      chrome.webstore.onInstallStageChanged.addListener(function(stage) {});
      chrome.webstore.install(
          undefined,
          function() {
            window.domAutomationController.send(true);
          },
          function(error) {
            console.log('Unexpected error: ' + error);
            window.domAutomationController.send(false);
          });
      // Force a garbage collection, so that if the callbacks aren't being
      // retained properly they'll get collected and the test will fail.
      window.gc();
    } catch (e) {
      console.log('Unexpected exception: ' + e);
      console.log(e.stack);
      window.domAutomationController.send(false);
      throw e;
    }
  }
</script>

</body>
</html>
